﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace GoodsModule.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class Init : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "WbGoods",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    GoodsCategoryId = table.Column<int>(type: "int", nullable: false),
                    Title = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false, comment: "标题")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Status = table.Column<ushort>(type: "smallint unsigned", nullable: false, comment: "状态"),
                    Sort = table.Column<uint>(type: "int unsigned", nullable: false, comment: "排序"),
                    StartTime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "开始时间"),
                    EndTime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "结束时间"),
                    Stock = table.Column<int>(type: "int", nullable: false, comment: "Stock"),
                    Exp = table.Column<decimal>(type: "decimal(9,2)", precision: 9, scale: 2, nullable: false, comment: "经验"),
                    Point = table.Column<decimal>(type: "decimal(9,2)", precision: 9, scale: 2, nullable: false, comment: "积分"),
                    Price = table.Column<decimal>(type: "decimal(9,2)", precision: 9, scale: 2, nullable: false, comment: "金额"),
                    Content = table.Column<string>(type: "longtext", nullable: false, comment: "内容")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    RowVersion = table.Column<DateTime>(type: "timestamp(6)", rowVersion: true, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WbGoods", x => x.Id);
                },
                comment: "商品")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "WbGoodsCategory",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    Title = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false, comment: "标题")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Sort = table.Column<int>(type: "int", nullable: false, comment: "排序"),
                    RowVersion = table.Column<DateTime>(type: "timestamp(6)", rowVersion: true, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WbGoodsCategory", x => x.Id);
                },
                comment: "商品分类")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "WbGoodsImage",
                columns: table => new
                {
                    Id = table.Column<long>(type: "bigint", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    IsDeleted = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    Sort = table.Column<uint>(type: "int unsigned", nullable: false, comment: "排序"),
                    Name = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "文件名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Path = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "文件路径")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Ext = table.Column<string>(type: "varchar(10)", maxLength: 10, nullable: false, comment: "扩展名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Size = table.Column<uint>(type: "int unsigned", nullable: false, comment: "文件大小"),
                    Title = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "标题")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Tags = table.Column<string>(type: "varchar(1000)", maxLength: 1000, nullable: false, comment: "标签")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    GoodsId = table.Column<int>(type: "int", nullable: true),
                    RowVersion = table.Column<DateTime>(type: "timestamp(6)", rowVersion: true, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WbGoodsImage", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WbGoodsImage_WbGoods_GoodsId",
                        column: x => x.GoodsId,
                        principalTable: "WbGoods",
                        principalColumn: "Id");
                },
                comment: "商品相册")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_WbGoods_IsDeleted",
                table: "WbGoods",
                column: "IsDeleted");

            migrationBuilder.CreateIndex(
                name: "IX_WbGoodsCategory_IsDeleted",
                table: "WbGoodsCategory",
                column: "IsDeleted");

            migrationBuilder.CreateIndex(
                name: "IX_WbGoodsImage_GoodsId",
                table: "WbGoodsImage",
                column: "GoodsId");

            migrationBuilder.CreateIndex(
                name: "IX_WbGoodsImage_IsDeleted",
                table: "WbGoodsImage",
                column: "IsDeleted");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "WbGoodsCategory");

            migrationBuilder.DropTable(
                name: "WbGoodsImage");

            migrationBuilder.DropTable(
                name: "WbGoods");
        }
    }
}
